package com.clay.appointment.controller.api;

import com.clay.appointment.common.page.PageInfo;
import com.clay.appointment.common.response.Result;
import com.clay.appointment.entity.hospital.Hospital;
import com.clay.appointment.service.DepartmentService;
import com.clay.appointment.service.HospitalService;
import com.clay.appointment.vo.hospital.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author : clay
 * @Description:
 * @Date: Create in 23:42 2021/8/22
 * @Modified By:
 */
@Api(tags = "预约挂号客户端")
@RestController
@RequestMapping("/api/hospital")
public class HospitalApiController {
    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;

    @ApiOperation(value = "查询医院列表")
    @GetMapping("findHospitalList/{page}/{limit}")
    public Result findHospitalList(@PathVariable("page") Integer page,
                                   @PathVariable("limit") Integer limit,
                                   HospitalQueryVo hospitalQueryVo) {
        PageInfo<Hospital> hospitalPageInfo = hospitalService.selectPage(page, limit, hospitalQueryVo);
        return Result.success(hospitalPageInfo);
    }

    @ApiOperation(value = "根据医院名称模糊查询")
    @GetMapping("findByLikeHospitalName/{hospitalName}")
    public Result findByLikeHospitalName(@PathVariable("hospitalName") String hospitalName) {
        List<Hospital> list = hospitalService.findByLikeHospitalName(hospitalName);
        return Result.success(list);
    }


    @ApiOperation(value = "根据医院编号获取科室列表")
    @GetMapping("department/{hospitalCode}")
    public Result index(
            @ApiParam(name = "hospitalCode", value = "医院code", required = true)
            @PathVariable("hospitalCode") String hospitalCode) {
        return Result.success(departmentService.findDepartmentTree(hospitalCode));
    }


    @ApiOperation(value = "根据医院编号获取医院预约挂号详情")
    @GetMapping("findHospitalDetail/{hospitalCode}")
    public Result item(
            @ApiParam(name = "hospitalCode", value = "医院code", required = true)
            @PathVariable("hospitalCode") String hospitalCode) {
        return Result.success(hospitalService.item(hospitalCode));
    }


}
